commonlibsse_ng\re\s/
ScrapHeap.rs1use crate::re::IMemoryStore::{IMemoryStore, IMemoryStoreVtbl};
2use crate::re::offsets_vtable::VTABLE_ScrapHeap;
3use crate::{re::offsets_rtti::RTTI_ScrapHeap, rel::id::VariantID};
4use core::ffi::c_void;
5use core::ptr;
6
7#[repr(C)]
8#[derive(Debug)]
9pub struct ScrapHeap {
10 pub __base: IMemoryStore,
11 pub smallBlocks: [*mut FreeBlock; 6], pub freeList: *mut FreeTreeNode, pub lastBlock: *mut Block, pub baseAddress: *mut c_void, pub endAddress: *mut c_void, pub commitEnd: *mut c_void, pub reserveSize: usize, pub minCommit: usize, pub totalAllocated: usize, pub keepPagesRequest: u32, pub totalFreeBlocks: u32, pub freeSmallBlocks: u32, pub totalAllocatedBlocks: u32, pub pmpBarrier: u32, }
26const _: () = assert!(core::mem::size_of::<ScrapHeap>() == 0x90);
27
28impl Default for ScrapHeap {
29 fn default() -> Self {
30 Self::new()
31 }
32}
33
34impl ScrapHeap {
35 pub const RTTI: VariantID = RTTI_ScrapHeap;
36 pub const VTABLE: [VariantID; 1] = VTABLE_ScrapHeap;
37
38 pub const fn new() -> Self {
39 Self {
40 __base: IMemoryStore::new(),
41 smallBlocks: [ptr::null_mut(); 6],
42 freeList: ptr::null_mut(),
43 lastBlock: ptr::null_mut(),
44 baseAddress: ptr::null_mut(),
45 endAddress: ptr::null_mut(),
46 commitEnd: ptr::null_mut(),
47 reserveSize: 1 << 26,
48 minCommit: 1 << 17,
49 totalAllocated: 0,
50 keepPagesRequest: 0,
51 totalFreeBlocks: 0,
52 freeSmallBlocks: 0,
53 totalAllocatedBlocks: 0,
54 pmpBarrier: 0,
55 }
56 }
57
58 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 66884, ae_id = 68144)]
59 pub unsafe fn allocate(&mut self, size: usize, alignment: usize) -> *mut c_void {}
60
61 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 66885, ae_id = 68146)]
62 pub unsafe fn deallocate(&mut self, mem: *mut c_void) -> *mut c_void {}
63}
64
65impl Drop for ScrapHeap {
66 fn drop(&mut self) {
67 use windows::Win32::System::Memory::{MEM_RELEASE, VirtualFree};
68
69 if let Err(_err) = unsafe { VirtualFree(self.baseAddress, 0, MEM_RELEASE) } {
70 #[cfg(feature = "tracing")]
71 tracing::error!("Failed `VirtualFree`: {_err}");
72 };
73 }
74}
75
76pub struct ScrapHeapVtbl {
77 pub __base: IMemoryStoreVtbl,
78}
79
80#[repr(C)]
81#[derive(Debug)]
82pub struct Block {
83 pub sizeFlags: usize, pub prev: *mut Block, }
86const _: () = assert!(core::mem::size_of::<Block>() == 0x10);
87
88#[repr(C)]
89#[derive(Debug)]
90pub struct FreeBlock {
91 pub __base: Block, pub left: *mut FreeBlock, pub right: *mut FreeBlock, }
95const _: () = assert!(core::mem::size_of::<FreeBlock>() == 0x20);
96
97#[repr(C)]
98#[derive(Debug)]
99pub struct FreeTreeNode {
100 pub __base: Block, pub root: *mut *mut FreeTreeNode, pub leftNode: *mut FreeTreeNode, pub rightNode: *mut FreeTreeNode, pub parentAndBlack: usize, }
106const _: () = assert!(core::mem::size_of::<FreeTreeNode>() == 0x30);